home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Aminet 1 (Walnut Creek)
/
Aminet - June 1993 [Walnut Creek].iso
/
usenet
/
sources
/
volume90
/
comm
/
uptime
/
part01
/
Uptime.mod
next >
Wrap
Text File
|
1990-10-14
|
4KB
|
115 lines
MODULE Uptime;
(*
how long has CD on serial device been active?
Stefan H-M Ludwig, Englischviertelstr. 47, CH-8032 Zuerich
sludwig@iiic.ethz.ch, cernvax!forty2!tll!ludwig
3 Sep 1990
Use "Run Uptime" to start it
Use "BREAK <process#>" to end it
Use "uptime ?" to see, how long CD has been active since last reset
Delete "S:Uptime.txt" to reset
*)
IMPORT
Arguments, Arts, ASCII, Dos, Exec, FileSystem, Hardware, SYSTEM;
FROM InOut IMPORT Write, WriteCard, WriteString, WriteLn;
CONST
delay = 100; (*2 secs @ 50, 1.67 @ 60 ticksPerSec*)
fileName = "S:Uptime.txt";
bufSize = SIZE (Dos.Date)+SIZE (LONGINT); (*creation + uptime*)
VAR
old, new, creation: Dos.Date;
oldPtr, newPtr, creationPtr: Dos.DatePtr;
file: FileSystem.File;
ticksPerSec, ticksPerHalf,
ticksPerMin, ticksPerHour, ticksPerDay, uptime: LONGINT;
(*
PROCEDURE CD (): BOOLEAN; (*is CD of serial active?*)
BEGIN (*CD*)
(*DoIO and cmdQuery would be cleaner :-)*)
RETURN ~(Hardware.comCD IN Hardware.ciab.pra); (*CD is active low!!*)
END CD;
*)
PROCEDURE WriteEsc (str: ARRAY OF CHAR);
BEGIN (*WriteEsc*)
Write (33C); Write ("["); WriteString (str); Write ("m");
END WriteEsc;
BEGIN (*Uptime*)
(*uptime := 0, done by M2*)
Arts.DetectCtrlC (FALSE);
oldPtr := SYSTEM.ADR (old); newPtr := SYSTEM.ADR (new);
creationPtr := SYSTEM.ADR (creation);
ticksPerSec := Exec.execBase^.powerSupplyFrequency;
ticksPerHalf := ticksPerSec DIV 2;
ticksPerMin := ticksPerSec * 60;
ticksPerHour := ticksPerMin * 60;
ticksPerDay := ticksPerHour * 24;
FileSystem.Lookup (file, fileName, bufSize, FALSE);
IF file.res # FileSystem.done THEN (*file doesn't exist yet*)
Dos.DateStamp (creationPtr);
FileSystem.Lookup (file, fileName, bufSize, TRUE); (*create it*)
FileSystem.WriteByteBlock (file, creation); (*write creation date*)
FileSystem.WriteByteBlock (file, uptime); (*write cummulated time = 0*)
ELSE
FileSystem.ReadByteBlock (file, creation); (*read creation date*)
FileSystem.ReadByteBlock (file, uptime); (*read old cummulated time*)
END;
Arts.Assert ((file.res = FileSystem.done) & (uptime >= 0),
SYSTEM.ADR (fileName));
Write (ASCII.ht); WriteEsc ("32");
WriteString ("UpTime, SHML, August '90"); WriteEsc ("31"); WriteLn;
IF Arguments.NumArgs () > 0 THEN
Dos.DateStamp (oldPtr); (*get today's date*)
WriteString ("Modem has been active since ");
DEC (old.days, creation.days);
Arts.Assert (old.days >=0, SYSTEM.ADR ("Set date to today"));
WriteCard (old.days, 0); WriteString (" day(s) for ");
WriteCard (uptime DIV ticksPerHour, 0); WriteString (" hr. ");
WriteCard ((uptime MOD ticksPerHour) DIV ticksPerMin, 0);
WriteString (" min. and ");
WriteCard ((uptime MOD ticksPerMin + ticksPerHalf) DIV ticksPerSec, 0);
WriteString (" sec."); WriteLn;
Write (ASCII.ht); WriteEsc ("33");
WriteString ("Delete "); WriteString (fileName);
WriteString (" to restart timer"); WriteEsc ("31"); WriteLn;
ELSE
LOOP (*Break with BREAK command*)
FileSystem.Close (file);
(*make sure, the file is closed when modem is down*)
WHILE Hardware.comCD IN Hardware.ciab.pra DO (*~CD ()*)
IF Dos.ctrlC IN Exec.SetSignal (SYSTEM.LONGSET {},
SYSTEM.LONGSET {}) THEN
EXIT;
END;
Dos.Delay (delay);
END; (*wait till CD*)
(*{CD}*)
Dos.DateStamp (oldPtr);
WHILE ~(Hardware.comCD IN Hardware.ciab.pra) DO (*CD()*)
IF Dos.ctrlC IN Exec.SetSignal (SYSTEM.LONGSET {},
SYSTEM.LONGSET {}) THEN
EXIT;
END;
Dos.Delay (delay);
END; (*wait till ~CD*)
(*{~CD}*)
Dos.DateStamp (newPtr);
INC (uptime,
(new.days-old.days)*ticksPerDay+
(new.minute-old.minute)*ticksPerMin+
(new.tick-old.tick)
);
FileSystem.Lookup (file, fileName, bufSize, FALSE);
Arts.Assert (file.res = FileSystem.done, SYSTEM.ADR (fileName));
FileSystem.SetPos (file, SIZE (Dos.Date)); (*skip creation date*)
FileSystem.WriteByteBlock (file, uptime); (*write new cummulated time*)
END; (*LOOP*)
END; (*IF*)
END Uptime.